package com.ruoyi.web.controller.robot;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.RobotWechatUser;
import com.ruoyi.system.service.IRobotWechatUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 微信用户登录
 */
@RestController
@RequestMapping("/robot/wechat")
public class RobotWecharUserController extends BaseController {

    @Autowired
    private IRobotWechatUserService robotWechatUserService;

    /**
     * 微信用户登录
     *
     * @param code
     * @return
     */
    @GetMapping("/login")
    public AjaxResult login(String code) {
        return success(robotWechatUserService.wechatLogin(code));
    }

    /**
     * 获取口令
     *
     * @param openid
     * @return
     */
    @GetMapping("/passwordcomand")
    public AjaxResult passwordcomand(String openid) {
        return success(robotWechatUserService.getUserPasswordCommand(openid));
    }

    /**
     * 更新微信用户基本信息
     *
     * @param robotWechatUser
     * @return
     */
    @PutMapping("/updateUserInfo")
    public AjaxResult updateUserInfo(@RequestBody RobotWechatUser robotWechatUser) {
        return success(robotWechatUserService.update(robotWechatUser, new LambdaQueryWrapper<RobotWechatUser>()
                .eq(RobotWechatUser::getOpenid, robotWechatUser.getOpenid())));
    }


}
